import 'package:flutter/widgets.dart';

// 没有动画的页面启动
class NoAnimRouteBuilder extends PageRouteBuilder{
  final Widget page;
  NoAnimRouteBuilder(this.page): super(
    opaque: false,
    pageBuilder: (context, animation, secondaryAnimation) => page,
    transitionDuration: Duration(microseconds: 0),
    transitionsBuilder: (context, animation, secondaryAnimation, child)=> child
  );
}

//渐入渐出动画
class FadeRouteBuilder extends PageRouteBuilder{
  final Widget page;
  FadeRouteBuilder(this.page): super(
    pageBuilder: (context, animation, secondaryAnimation) =>page,
    transitionDuration: Duration(milliseconds: 500),
    transitionsBuilder: (context, animation, secondaryAnimation, child) =>
        FadeTransition(
          opacity: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
            parent: animation,
            curve: Curves.fastOutSlowIn,
          )),
          child: child,
        )
  );
}

//从右到左移动效果
class SlideTopRouteBuilder extends PageRouteBuilder{
  final Widget page;
  SlideTopRouteBuilder(this.page): super(
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: Duration(milliseconds: 500),
      transitionsBuilder: (context, animation, secondaryAnimation, child) =>
          SlideTransition(
            position: Tween<Offset>(begin: Offset(1.0, 0.0), end: Offset(0.0, 0.0))
                .animate(CurvedAnimation(
                parent: animation, curve: Curves.fastOutSlowIn)),
            child: child,
          )
  );
}

//缩放效果
class ScaleRouteBuilder extends PageRouteBuilder{
  final Widget page;
  ScaleRouteBuilder(this.page): super(
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: Duration(milliseconds: 500),
      transitionsBuilder: (context, animation, secondaryAnimation, child) =>
          ScaleTransition(
            scale: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
              parent: animation,
              curve: Curves.fastOutSlowIn
            )),
            child: child,
          )
  );
}

//旋转效果
class RotationRouteBuilder extends PageRouteBuilder{
  final Widget page;
  RotationRouteBuilder(this.page): super(
      pageBuilder: (context, animation, secondaryAnimation) => page,
      transitionDuration: Duration(milliseconds: 500),
      transitionsBuilder: (context, animation, secondaryAnimation, child) =>
          RotationTransition(
            turns: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                parent: animation,
                curve: Curves.fastOutSlowIn
            )),
            child: ScaleTransition(
              scale: Tween(begin: 0.0, end: 1.0).animate(CurvedAnimation(
                parent: animation,
                curve: Curves.fastOutSlowIn
              )),
              child: child,
            ),
          )
  );
}